<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>png++: convert_color_space.hpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">png++
   &#160;<span id="projectnumber">0.2.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">convert_color_space.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="convert__color__space_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2007,2008   Alex Shulgin</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * This file is part of png++ the C++ wrapper for libpng.  PNG++ is free</span>
<a name="l00005"></a>00005 <span class="comment"> * software; the exact copying conditions are as follows:</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Redistribution and use in source and binary forms, with or without</span>
<a name="l00008"></a>00008 <span class="comment"> * modification, are permitted provided that the following conditions are met:</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * 1. Redistributions of source code must retain the above copyright notice,</span>
<a name="l00011"></a>00011 <span class="comment"> * this list of conditions and the following disclaimer.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00014"></a>00014 <span class="comment"> * notice, this list of conditions and the following disclaimer in the</span>
<a name="l00015"></a>00015 <span class="comment"> * documentation and/or other materials provided with the distribution.</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * 3. The name of the author may not be used to endorse or promote products</span>
<a name="l00018"></a>00018 <span class="comment"> * derived from this software without specific prior written permission.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS&#39;&#39; AND ANY EXPRESS OR</span>
<a name="l00021"></a>00021 <span class="comment"> * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</span>
<a name="l00022"></a>00022 <span class="comment"> * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN</span>
<a name="l00023"></a>00023 <span class="comment"> * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00024"></a>00024 <span class="comment"> * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED</span>
<a name="l00025"></a>00025 <span class="comment"> * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR</span>
<a name="l00026"></a>00026 <span class="comment"> * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span>
<a name="l00027"></a>00027 <span class="comment"> * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
<a name="l00028"></a>00028 <span class="comment"> * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00029"></a>00029 <span class="comment"> * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00030"></a>00030 <span class="comment"> */</span>
<a name="l00031"></a>00031 <span class="preprocessor">#ifndef PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#define PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="error_8hpp.html">error.hpp</a>&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="rgb__pixel_8hpp.html">rgb_pixel.hpp</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="rgba__pixel_8hpp.html">rgba_pixel.hpp</a>&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="gray__pixel_8hpp.html">gray_pixel.hpp</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="ga__pixel_8hpp.html">ga_pixel.hpp</a>&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="index__pixel_8hpp.html">index_pixel.hpp</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="reader_8hpp.html">reader.hpp</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="writer_8hpp.html">writer.hpp</a>&quot;</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="keyword">namespace </span>png
<a name="l00044"></a>00044 {
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="namespacepng_1_1detail.html">00046</a>     <span class="keyword">namespace </span>detail
<a name="l00047"></a>00047     {
<a name="l00048"></a>00048 
<a name="l00053"></a>00053         <span class="keyword">template</span>&lt; <span class="keyword">typename</span> pixel &gt;
<a name="l00054"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html">00054</a>         <span class="keyword">struct </span><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html" title="IO transformation class template. Converts image color space.">convert_color_space_impl</a>
<a name="l00055"></a>00055         {
<a name="l00056"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#aaab05b7d03ad13294c6d3d93b2cb74f4">00056</a>             <span class="keyword">typedef</span> pixel_traits&lt; pixel &gt; <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#aaab05b7d03ad13294c6d3d93b2cb74f4">traits</a>;
<a name="l00057"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ad95dcf5a0fa7cdbf9a3151d6f82181a5">00057</a>             <span class="keyword">typedef</span> <span class="keyword">typename</span> traits::component_type <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ad95dcf5a0fa7cdbf9a3151d6f82181a5">component_type</a>;
<a name="l00058"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a0c9185f5bbe9c0b7b28cc2b2b6439c0d">00058</a>             <span class="keyword">typedef</span> <a class="code" href="structpng_1_1basic__alpha__pixel__traits.html" title="Basic pixel traits class template for pixels with alpha channel.">basic_alpha_pixel_traits&lt; component_type &gt;</a> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a0c9185f5bbe9c0b7b28cc2b2b6439c0d">alpha_traits</a>;
<a name="l00059"></a>00059 
<a name="l00060"></a>00060             <span class="keyword">template</span>&lt; <span class="keyword">class</span> reader &gt;
<a name="l00061"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae34dba16ec7a6b23d455b30ddfaa0d6d">00061</a>             <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae34dba16ec7a6b23d455b30ddfaa0d6d">operator()</a>(<a class="code" href="classpng_1_1reader.html" title="The PNG reader class template. This is the low-level reading interface--use image class or consumer c...">reader</a>&amp; io)<span class="keyword"> const</span>
<a name="l00062"></a>00062 <span class="keyword">            </span>{
<a name="l00063"></a>00063                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a5b4540ba76df4cc4ce7becd5b701c215">handle_16</a>(io);
<a name="l00064"></a>00064                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae6d8c742aceeb6bd4045030d1839e099">handle_alpha</a>(io, <a class="code" href="structpng_1_1basic__alpha__pixel__traits.html#af3f691488f7e50f4541e0462d2310b17" title="Returns the default alpha channel filler for full opacity.">alpha_traits::get_alpha_filler</a>());
<a name="l00065"></a>00065                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a6d47f40d7acabc8b7417e5a75bb45298">handle_palette</a>(io);
<a name="l00066"></a>00066                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#aabda009d0f40f092d98a4b092e29dbc8">handle_rgb</a>(io);
<a name="l00067"></a>00067                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae1a7d10063a248ee5fdca917a5154d12">handle_gray</a>(io);
<a name="l00068"></a>00068 
<a name="l00069"></a>00069                 io.<a class="code" href="classpng_1_1io__base.html#a513fdbaa4edc5249da2ce8319521b222">set_color_type</a>(traits::get_color_type());
<a name="l00070"></a>00070                 io.<a class="code" href="classpng_1_1io__base.html#afc85421463d684509709e5efbf5ca7d0">set_bit_depth</a>(traits::get_bit_depth());
<a name="l00071"></a>00071             }
<a name="l00072"></a>00072 
<a name="l00073"></a>00073         <span class="keyword">protected</span>:
<a name="l00074"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a5caef70198d33621461d4dd93a03d80d">00074</a>             <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a5caef70198d33621461d4dd93a03d80d">expand_8_to_16</a>(png_struct*, png_row_info* row_info,
<a name="l00075"></a>00075                                        <a class="code" href="namespacepng.html#ac0e0e2e09bdd9a287618bfdc5f31ca52">byte</a>* row)
<a name="l00076"></a>00076             {
<a name="l00077"></a>00077 <span class="preprocessor">#ifdef DEBUG_EXPAND_8_16</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span>                printf(<span class="stringliteral">&quot;row: width=%d, bytes=%d, channels=%d\n&quot;</span>,
<a name="l00079"></a>00079                        row_info-&gt;width, row_info-&gt;rowbytes, row_info-&gt;channels);
<a name="l00080"></a>00080                 printf(<span class="stringliteral">&quot;&lt;= &quot;</span>);
<a name="l00081"></a>00081                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#adf203d1ef4c2ad91250dcbd5d9a00d56">dump_row</a>(row, row_info-&gt;rowbytes);
<a name="l00082"></a>00082 <span class="preprocessor">#endif</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span>                <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = row_info-&gt;rowbytes; i-- &gt; 0; )
<a name="l00084"></a>00084                 {
<a name="l00085"></a>00085                     row[2*i + 1] = row[i];
<a name="l00086"></a>00086                     row[2*i + 0] = 0;
<a name="l00087"></a>00087                 }
<a name="l00088"></a>00088 <span class="preprocessor">#ifdef DEBUG_EXPAND_8_16</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span>                printf(<span class="stringliteral">&quot;=&gt; &quot;</span>);
<a name="l00090"></a>00090                 <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#adf203d1ef4c2ad91250dcbd5d9a00d56">dump_row</a>(row, 2*row_info-&gt;rowbytes);
<a name="l00091"></a>00091 <span class="preprocessor">#endif</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span>            }
<a name="l00093"></a>00093 
<a name="l00094"></a>00094 <span class="preprocessor">#ifdef DEBUG_EXPAND_8_16</span>
<a name="l00095"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#adf203d1ef4c2ad91250dcbd5d9a00d56">00095</a> <span class="preprocessor"></span>            <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#adf203d1ef4c2ad91250dcbd5d9a00d56">dump_row</a>(<a class="code" href="namespacepng.html#ac0e0e2e09bdd9a287618bfdc5f31ca52">byte</a> <span class="keyword">const</span>* row, <span class="keywordtype">size_t</span> width)
<a name="l00096"></a>00096             {
<a name="l00097"></a>00097                 printf(<span class="stringliteral">&quot;{&quot;</span>);
<a name="l00098"></a>00098                 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; width; ++i)
<a name="l00099"></a>00099                 {
<a name="l00100"></a>00100                     printf(<span class="stringliteral">&quot; %02x,&quot;</span>, row[i]);
<a name="l00101"></a>00101                 }
<a name="l00102"></a>00102                 printf(<span class="stringliteral">&quot; }\n&quot;</span>);
<a name="l00103"></a>00103             }
<a name="l00104"></a>00104 <span class="preprocessor">#endif</span>
<a name="l00105"></a>00105 <span class="preprocessor"></span>
<a name="l00106"></a>00106             <span class="keyword">template</span>&lt; <span class="keyword">class</span> reader &gt;
<a name="l00107"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a5b4540ba76df4cc4ce7becd5b701c215">00107</a>             <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a5b4540ba76df4cc4ce7becd5b701c215">handle_16</a>(<a class="code" href="classpng_1_1reader.html" title="The PNG reader class template. This is the low-level reading interface--use image class or consumer c...">reader</a>&amp; io)
<a name="l00108"></a>00108             {
<a name="l00109"></a>00109                 <span class="keywordflow">if</span> (io.<a class="code" href="classpng_1_1io__base.html#a391152531f1825e81460b9847a3a8000">get_bit_depth</a>() == 16 &amp;&amp; traits::get_bit_depth() == 8)
<a name="l00110"></a>00110                 {
<a name="l00111"></a>00111 <span class="preprocessor">#ifdef PNG_READ_16_TO_8_SUPPORTED</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#ad801a397266597a8f64f3a983cc9c866">set_strip_16</a>();
<a name="l00113"></a>00113 <span class="preprocessor">#else</span>
<a name="l00114"></a>00114 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;expected 8-bit data but found 16-bit;&quot;</span>
<a name="l00115"></a>00115                                 <span class="stringliteral">&quot; recompile with PNG_READ_16_TO_8_SUPPORTED&quot;</span>);
<a name="l00116"></a>00116 <span class="preprocessor">#endif</span>
<a name="l00117"></a>00117 <span class="preprocessor"></span>                }
<a name="l00118"></a>00118                 <span class="keywordflow">if</span> (io.<a class="code" href="classpng_1_1io__base.html#a391152531f1825e81460b9847a3a8000">get_bit_depth</a>() != 16 &amp;&amp; traits::get_bit_depth() == 16)
<a name="l00119"></a>00119                 {
<a name="l00120"></a>00120 <span class="preprocessor">#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED</span>
<a name="l00121"></a>00121 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#ad4798a1cabbd2d6956184e154de0e7bd">set_read_user_transform</a>(<a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a5caef70198d33621461d4dd93a03d80d">expand_8_to_16</a>);
<a name="l00122"></a>00122                     io.<a class="code" href="classpng_1_1io__base.html#abf283c5d396276f539597ae1922ea61d">set_user_transform_info</a>(NULL, 16,
<a name="l00123"></a>00123                                                traits::get_channels());
<a name="l00124"></a>00124 <span class="preprocessor">#else</span>
<a name="l00125"></a>00125 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;expected 16-bit data but found 8-bit;&quot;</span>
<a name="l00126"></a>00126                                 <span class="stringliteral">&quot; recompile with&quot;</span>
<a name="l00127"></a>00127                                 <span class="stringliteral">&quot; PNG_READ_USER_TRANSFORM_SUPPORTED&quot;</span>);
<a name="l00128"></a>00128 <span class="preprocessor">#endif</span>
<a name="l00129"></a>00129 <span class="preprocessor"></span>                }
<a name="l00130"></a>00130             }
<a name="l00131"></a>00131 
<a name="l00132"></a>00132             <span class="keyword">template</span>&lt; <span class="keyword">class</span> reader &gt;
<a name="l00133"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae6d8c742aceeb6bd4045030d1839e099">00133</a>             <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae6d8c742aceeb6bd4045030d1839e099">handle_alpha</a>(<a class="code" href="classpng_1_1reader.html" title="The PNG reader class template. This is the low-level reading interface--use image class or consumer c...">reader</a>&amp; io, <a class="code" href="namespacepng.html#a76064164adfdd2316adebf0a4fb83873">uint_32</a> filler)
<a name="l00134"></a>00134             {
<a name="l00135"></a>00135                 <span class="keywordtype">bool</span> src_alpha = (io.<a class="code" href="classpng_1_1io__base.html#ab8070ca679dfb49c226978297e7b4c08">get_color_type</a>() &amp; <a class="code" href="namespacepng.html#a6f486c6b94f23abf89e4c7b22aa363d9a0440ff4e35dcd2df72078e852664404f">color_mask_alpha</a>);
<a name="l00136"></a>00136                 <span class="keywordtype">bool</span> src_tRNS = io.<a class="code" href="classpng_1_1io__base.html#a183571c721c9da3eebe056877e1b84ff">has_chunk</a>(<a class="code" href="namespacepng.html#a93bd423c4b470bcea62b3664e835ec87aef2ac03a3d930bb1701988dae298a1af">chunk_tRNS</a>);
<a name="l00137"></a>00137                 <span class="keywordtype">bool</span> dst_alpha = traits::get_color_type() &amp; <a class="code" href="namespacepng.html#a6f486c6b94f23abf89e4c7b22aa363d9a0440ff4e35dcd2df72078e852664404f">color_mask_alpha</a>;
<a name="l00138"></a>00138                 <span class="keywordflow">if</span> ((src_alpha || src_tRNS) &amp;&amp; !dst_alpha)
<a name="l00139"></a>00139                 {
<a name="l00140"></a>00140 <span class="preprocessor">#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED</span>
<a name="l00141"></a>00141 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#ab1c8dc7c170befd8a12c4bb286a91295">set_strip_alpha</a>();
<a name="l00142"></a>00142 <span class="preprocessor">#else</span>
<a name="l00143"></a>00143 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;alpha channel unexpected;&quot;</span>
<a name="l00144"></a>00144                                 <span class="stringliteral">&quot; recompile with&quot;</span>
<a name="l00145"></a>00145                                 <span class="stringliteral">&quot; PNG_READ_STRIP_ALPHA_SUPPORTED&quot;</span>);
<a name="l00146"></a>00146 <span class="preprocessor">#endif</span>
<a name="l00147"></a>00147 <span class="preprocessor"></span>                }
<a name="l00148"></a>00148                 <span class="keywordflow">if</span> (!src_alpha &amp;&amp; dst_alpha)
<a name="l00149"></a>00149                 {
<a name="l00150"></a>00150 <span class="preprocessor">#if defined(PNG_tRNS_SUPPORTED) &amp;&amp; defined(PNG_READ_EXPAND_SUPPORTED)</span>
<a name="l00151"></a>00151 <span class="preprocessor"></span>                    <span class="keywordflow">if</span> (src_tRNS)
<a name="l00152"></a>00152                     {
<a name="l00153"></a>00153                         io.<a class="code" href="classpng_1_1io__base.html#a43bc25cb81b37fecf4851fcf6ebb26ce">set_tRNS_to_alpha</a>();
<a name="l00154"></a>00154                         <span class="keywordflow">return</span>;
<a name="l00155"></a>00155                     }
<a name="l00156"></a>00156 <span class="preprocessor">#endif</span>
<a name="l00157"></a>00157 <span class="preprocessor"></span><span class="preprocessor">#if defined(PNG_READ_FILLER_SUPPORTED) &amp;&amp; !defined(PNG_1_0_X)</span>
<a name="l00158"></a>00158 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#a20d77b4fe7e6232a383455bd021e569e">set_add_alpha</a>(filler, <a class="code" href="namespacepng.html#a45c793e9e2229e38e935486c95962fe4a3e8aa76d0dfd9fd5a0d4568b44ce5a6f">filler_after</a>);
<a name="l00159"></a>00159 <span class="preprocessor">#else</span>
<a name="l00160"></a>00160 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;expected alpha channel but none found;&quot;</span>
<a name="l00161"></a>00161                                 <span class="stringliteral">&quot; recompile with PNG_READ_FILLER_SUPPORTED&quot;</span>
<a name="l00162"></a>00162                                 <span class="stringliteral">&quot; and be sure to use libpng &gt; 1.0.x&quot;</span>);
<a name="l00163"></a>00163 <span class="preprocessor">#endif</span>
<a name="l00164"></a>00164 <span class="preprocessor"></span>                }
<a name="l00165"></a>00165             }
<a name="l00166"></a>00166 
<a name="l00167"></a>00167             <span class="keyword">template</span>&lt; <span class="keyword">class</span> reader &gt;
<a name="l00168"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a6d47f40d7acabc8b7417e5a75bb45298">00168</a>             <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#a6d47f40d7acabc8b7417e5a75bb45298">handle_palette</a>(<a class="code" href="classpng_1_1reader.html" title="The PNG reader class template. This is the low-level reading interface--use image class or consumer c...">reader</a>&amp; io)
<a name="l00169"></a>00169             {
<a name="l00170"></a>00170                 <span class="keywordflow">if</span> (io.<a class="code" href="classpng_1_1io__base.html#ab8070ca679dfb49c226978297e7b4c08">get_color_type</a>() == <a class="code" href="namespacepng.html#a4f30149e7da9c8d70e84e6977a7f74daa11ca0096a8c002514f3ba1599a42d407">color_type_palette</a>)
<a name="l00171"></a>00171                 {
<a name="l00172"></a>00172 <span class="preprocessor">#ifdef PNG_READ_EXPAND_SUPPORTED</span>
<a name="l00173"></a>00173 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#a551d63cd2c32d66d8ecdb5b50061fed6">set_palette_to_rgb</a>();
<a name="l00174"></a>00174 
<a name="l00175"></a>00175                     <span class="keywordflow">if</span> (traits::get_color_type() != <a class="code" href="namespacepng.html#a4f30149e7da9c8d70e84e6977a7f74daa11ca0096a8c002514f3ba1599a42d407">color_type_palette</a>)
<a name="l00176"></a>00176                     {
<a name="l00177"></a>00177                         io.<a class="code" href="classpng_1_1io__base.html#a18cfaa6714239cf81ecac6565f5d0913">get_info</a>().<a class="code" href="classpng_1_1image__info.html#a254c2504eba5a409b23017b2a6f5427e" title="Removes all entries from the palette.">drop_palette</a>();
<a name="l00178"></a>00178                     }
<a name="l00179"></a>00179 <span class="preprocessor">#else</span>
<a name="l00180"></a>00180 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;indexed colors unexpected;&quot;</span>
<a name="l00181"></a>00181                                 <span class="stringliteral">&quot; recompile with PNG_READ_EXPAND_SUPPORTED&quot;</span>);
<a name="l00182"></a>00182 <span class="preprocessor">#endif</span>
<a name="l00183"></a>00183 <span class="preprocessor"></span>                }
<a name="l00184"></a>00184             }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186             <span class="keyword">template</span>&lt; <span class="keyword">class</span> reader &gt;
<a name="l00187"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#aabda009d0f40f092d98a4b092e29dbc8">00187</a>             <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#aabda009d0f40f092d98a4b092e29dbc8">handle_rgb</a>(<a class="code" href="classpng_1_1reader.html" title="The PNG reader class template. This is the low-level reading interface--use image class or consumer c...">reader</a>&amp; io)
<a name="l00188"></a>00188             {
<a name="l00189"></a>00189                 <span class="keywordtype">bool</span> src_rgb =
<a name="l00190"></a>00190                     io.<a class="code" href="classpng_1_1io__base.html#ab8070ca679dfb49c226978297e7b4c08">get_color_type</a>() &amp; (<a class="code" href="namespacepng.html#a6f486c6b94f23abf89e4c7b22aa363d9a6afeb13ddede12a9c9f5a3397dc67e6b">color_mask_rgb</a> | <a class="code" href="namespacepng.html#a6f486c6b94f23abf89e4c7b22aa363d9ab28c70d43713dc3744e19b519793080a">color_mask_palette</a>);
<a name="l00191"></a>00191                 <span class="keywordtype">bool</span> dst_rgb = traits::get_color_type() &amp; <a class="code" href="namespacepng.html#a6f486c6b94f23abf89e4c7b22aa363d9a6afeb13ddede12a9c9f5a3397dc67e6b">color_mask_rgb</a>;
<a name="l00192"></a>00192                 <span class="keywordflow">if</span> (src_rgb &amp;&amp; !dst_rgb)
<a name="l00193"></a>00193                 {
<a name="l00194"></a>00194 <span class="preprocessor">#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED</span>
<a name="l00195"></a>00195 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#a8e9771d816eee5d3f39f3c1486130525">set_rgb_to_gray</a>(<span class="comment">/*rgb_to_gray_error*/</span>);
<a name="l00196"></a>00196 <span class="preprocessor">#else</span>
<a name="l00197"></a>00197 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;grayscale data expected;&quot;</span>
<a name="l00198"></a>00198                                 <span class="stringliteral">&quot; recompile with&quot;</span>
<a name="l00199"></a>00199                                 <span class="stringliteral">&quot; PNG_READ_RGB_TO_GRAY_SUPPORTED&quot;</span>);
<a name="l00200"></a>00200 <span class="preprocessor">#endif</span>
<a name="l00201"></a>00201 <span class="preprocessor"></span>                }
<a name="l00202"></a>00202                 <span class="keywordflow">if</span> (!src_rgb &amp;&amp; dst_rgb)
<a name="l00203"></a>00203                 {
<a name="l00204"></a>00204 <span class="preprocessor">#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED</span>
<a name="l00205"></a>00205 <span class="preprocessor"></span>                    io.<a class="code" href="classpng_1_1io__base.html#aeec721b9743dd97861377a44e0a4c999">set_gray_to_rgb</a>();
<a name="l00206"></a>00206 <span class="preprocessor">#else</span>
<a name="l00207"></a>00207 <span class="preprocessor"></span>                    <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;expected RGB data;&quot;</span>
<a name="l00208"></a>00208                                 <span class="stringliteral">&quot; recompile with&quot;</span>
<a name="l00209"></a>00209                                 <span class="stringliteral">&quot; PNG_READ_GRAY_TO_RGB_SUPPORTED&quot;</span>);
<a name="l00210"></a>00210 <span class="preprocessor">#endif</span>
<a name="l00211"></a>00211 <span class="preprocessor"></span>                }
<a name="l00212"></a>00212             }
<a name="l00213"></a>00213 
<a name="l00214"></a>00214             <span class="keyword">template</span>&lt; <span class="keyword">class</span> reader &gt;
<a name="l00215"></a><a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae1a7d10063a248ee5fdca917a5154d12">00215</a>             <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="structpng_1_1detail_1_1convert__color__space__impl.html#ae1a7d10063a248ee5fdca917a5154d12">handle_gray</a>(<a class="code" href="classpng_1_1reader.html" title="The PNG reader class template. This is the low-level reading interface--use image class or consumer c...">reader</a>&amp; io)
<a name="l00216"></a>00216             {
<a name="l00217"></a>00217                 <span class="keywordflow">if</span> ((io.<a class="code" href="classpng_1_1io__base.html#ab8070ca679dfb49c226978297e7b4c08">get_color_type</a>() &amp; ~<a class="code" href="namespacepng.html#a6f486c6b94f23abf89e4c7b22aa363d9a0440ff4e35dcd2df72078e852664404f">color_mask_alpha</a>)
<a name="l00218"></a>00218                     == <a class="code" href="namespacepng.html#a4f30149e7da9c8d70e84e6977a7f74daa0c175d7c5fff3387508ad5cbb7fc456c">color_type_gray</a>)
<a name="l00219"></a>00219                 {
<a name="l00220"></a>00220                     <span class="keywordflow">if</span> (io.<a class="code" href="classpng_1_1io__base.html#a391152531f1825e81460b9847a3a8000">get_bit_depth</a>() &lt; 8 &amp;&amp; traits::get_bit_depth() &gt;= 8)
<a name="l00221"></a>00221                     {
<a name="l00222"></a>00222 <span class="preprocessor">#ifdef PNG_READ_EXPAND_SUPPORTED</span>
<a name="l00223"></a>00223 <span class="preprocessor"></span>                        io.<a class="code" href="classpng_1_1io__base.html#ab33730e38ea2fe21c59557df6ad7d78b">set_gray_1_2_4_to_8</a>();
<a name="l00224"></a>00224 <span class="preprocessor">#else</span>
<a name="l00225"></a>00225 <span class="preprocessor"></span>                        <span class="keywordflow">throw</span> <a class="code" href="classpng_1_1error.html" title="Exception class to represent runtime errors related to png++ operation.">error</a>(<span class="stringliteral">&quot;convert_color_space: expected 8-bit data;&quot;</span>
<a name="l00226"></a>00226                                     <span class="stringliteral">&quot; recompile with&quot;</span>
<a name="l00227"></a>00227                                     <span class="stringliteral">&quot; PNG_READ_EXPAND_SUPPORTED&quot;</span>);
<a name="l00228"></a>00228 <span class="preprocessor">#endif</span>
<a name="l00229"></a>00229 <span class="preprocessor"></span>                    }
<a name="l00230"></a>00230                 }
<a name="l00231"></a>00231             }
<a name="l00232"></a>00232         };
<a name="l00233"></a>00233 
<a name="l00234"></a>00234     } <span class="comment">// namespace detal</span>
<a name="l00235"></a>00235 
<a name="l00251"></a>00251     <span class="keyword">template</span>&lt; <span class="keyword">typename</span> pixel &gt;
<a name="l00252"></a><a class="code" href="structpng_1_1convert__color__space.html">00252</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>
<a name="l00253"></a>00253     {
<a name="l00254"></a>00254     };
<a name="l00255"></a>00255 
<a name="l00260"></a>00260     <span class="keyword">template</span>&lt;&gt;
<a name="l00261"></a><a class="code" href="structpng_1_1convert__color__space_3_01rgb__pixel_01_4.html">00261</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="structpng_1_1basic__rgb__pixel.html" title="RGB pixel type.">rgb_pixel</a> &gt;
<a name="l00262"></a>00262         : detail::convert_color_space_impl&lt; rgb_pixel &gt;
<a name="l00263"></a>00263     {
<a name="l00264"></a>00264     };
<a name="l00265"></a>00265 
<a name="l00270"></a>00270     <span class="keyword">template</span>&lt;&gt;
<a name="l00271"></a><a class="code" href="structpng_1_1convert__color__space_3_01rgb__pixel__16_01_4.html">00271</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="structpng_1_1basic__rgb__pixel.html" title="RGB pixel type.">rgb_pixel_16</a> &gt;
<a name="l00272"></a>00272         : detail::convert_color_space_impl&lt; rgb_pixel_16 &gt;
<a name="l00273"></a>00273     {
<a name="l00274"></a>00274     };
<a name="l00275"></a>00275 
<a name="l00280"></a>00280     <span class="keyword">template</span>&lt;&gt;
<a name="l00281"></a><a class="code" href="structpng_1_1convert__color__space_3_01rgba__pixel_01_4.html">00281</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="structpng_1_1basic__rgba__pixel.html" title="RGBA pixel type.">rgba_pixel</a> &gt;
<a name="l00282"></a>00282         : detail::convert_color_space_impl&lt; rgba_pixel &gt;
<a name="l00283"></a>00283     {
<a name="l00284"></a>00284     };
<a name="l00285"></a>00285 
<a name="l00290"></a>00290     <span class="keyword">template</span>&lt;&gt;
<a name="l00291"></a><a class="code" href="structpng_1_1convert__color__space_3_01rgba__pixel__16_01_4.html">00291</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="structpng_1_1basic__rgba__pixel.html" title="RGBA pixel type.">rgba_pixel_16</a> &gt;
<a name="l00292"></a>00292         : detail::convert_color_space_impl&lt; rgba_pixel_16 &gt;
<a name="l00293"></a>00293     {
<a name="l00294"></a>00294     };
<a name="l00295"></a>00295 
<a name="l00300"></a>00300     <span class="keyword">template</span>&lt;&gt;
<a name="l00301"></a><a class="code" href="structpng_1_1convert__color__space_3_01gray__pixel_01_4.html">00301</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="namespacepng.html#a8e371483a14270cadcd853b3d4c1b3ba" title="The 8-bit Grayscale pixel type.">gray_pixel</a> &gt;
<a name="l00302"></a>00302         : detail::convert_color_space_impl&lt; gray_pixel &gt;
<a name="l00303"></a>00303     {
<a name="l00304"></a>00304     };
<a name="l00305"></a>00305 
<a name="l00310"></a>00310     <span class="keyword">template</span>&lt;&gt;
<a name="l00311"></a><a class="code" href="structpng_1_1convert__color__space_3_01gray__pixel__16_01_4.html">00311</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="namespacepng.html#ade60813c0f7001929969853b91e9144e" title="The 16-bit Grayscale pixel type.">gray_pixel_16</a> &gt;
<a name="l00312"></a>00312         : detail::convert_color_space_impl&lt; gray_pixel_16 &gt;
<a name="l00313"></a>00313     {
<a name="l00314"></a>00314     };
<a name="l00315"></a>00315 
<a name="l00320"></a>00320     <span class="keyword">template</span>&lt;&gt;
<a name="l00321"></a><a class="code" href="structpng_1_1convert__color__space_3_01ga__pixel_01_4.html">00321</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="structpng_1_1basic__ga__pixel.html" title="Basic Gray+Alpha pixel type.">ga_pixel</a> &gt;
<a name="l00322"></a>00322         : detail::convert_color_space_impl&lt; ga_pixel &gt;
<a name="l00323"></a>00323     {
<a name="l00324"></a>00324     };
<a name="l00325"></a>00325 
<a name="l00330"></a>00330     <span class="keyword">template</span>&lt;&gt;
<a name="l00331"></a><a class="code" href="structpng_1_1convert__color__space_3_01ga__pixel__16_01_4.html">00331</a>     <span class="keyword">struct </span><a class="code" href="structpng_1_1convert__color__space.html" title="IO transformation class template. Converts image color space.">convert_color_space</a>&lt; <a class="code" href="structpng_1_1basic__ga__pixel.html" title="Basic Gray+Alpha pixel type.">ga_pixel_16</a> &gt;
<a name="l00332"></a>00332         : detail::convert_color_space_impl&lt; ga_pixel_16 &gt;
<a name="l00333"></a>00333     {
<a name="l00334"></a>00334     };
<a name="l00335"></a>00335 
<a name="l00336"></a>00336 } <span class="comment">// namespace png</span>
<a name="l00337"></a>00337 
<a name="l00338"></a>00338 <span class="preprocessor">#endif // PNGPP_CONVERT_COLOR_SPACE_HPP_INCLUDED</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Jan 25 2013 14:10:10 for png++ by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
